package ru.ncedu.java.vlku.hrs.uil.cmd;

import ru.ncedu.java.vlku.hrs.bll.HRSManager;
import ru.ncedu.java.vlku.hrs.bll.HRSManagerFactory;
import ru.ncedu.java.vlku.hrs.model.Cargo;
import ru.ncedu.java.vlku.hrs.model.Price;
import ru.ncedu.java.vlku.hrs.model.Tariff;

public class CreatePrice implements Command {
    // create price <cargo_id> <tariff_id> <price>
    @Override
    public void execute(String[] args) {
        if (args.length != 5)
            throw new IllegalArgumentException();
        Long cargo_id = Long.parseLong(args[2]);
        Long tariff_id = Long.parseLong(args[3]);
        Long prval = Long.parseLong(args[4]);

        HRSManager manager = HRSManagerFactory.getInstance().getHRSManager();
        Cargo cargo = manager.getCargoById(cargo_id);
        Tariff tariff = manager.getTariffById(tariff_id);
        Price price = new Price(cargo, tariff, prval);
        manager.createPrice(price);
    }
}
